package com.huaxiafinance.management.controller;

import com.huaxiafinance.management.dto.request.InviteDto;
import com.huaxiafinance.management.service.UserInviteService;
import com.huaxiafinance.management.util.MessageResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;


@Controller("userInviteController")
@RequestMapping("/userInvite")
public class UserInviteController {

  protected Logger logger = Logger.getLogger(UserInviteController.class);
  @Autowired
  private UserInviteService userInviteService;

  /**
   * 请求用戶邀請列表
   */
  @RequestMapping(value = "/queryInviteDetails", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String queryInviteDetails(@Valid @RequestBody InviteDto dto, BindingResult bindingResult) {
    logger.info("请求用戶邀請列表参数：" + dto.toString());
    MessageResult messageResult = new MessageResult();
    if (bindingResult.hasErrors()) {
      messageResult.setFailureResult(bindingResult);
    } else {
      try {
        messageResult = userInviteService.queryInviteDetails(dto);
      } catch (Exception e) {
        messageResult.setFailureResult();
        logger.info("请求积分触发列表异常原因：" + e);
      }
    }
    logger.info("请求用戶邀請列表返回参数：" + messageResult.getAsJSON());
    return messageResult.getAsJSON();
  }


}
